package com.fyzk.activity.user;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.activity.dialog.DialogActivity;
import com.fyzk.bean.BankListResponse;
import com.tyjc.lottery.R;
import com.fyzk.net.PublicMethod;

import java.util.ArrayList;
import java.util.List;


public class TiXianBankCheckActivity extends DialogActivity{

	private View view;
	private TextView num_tv;
	private LinearLayout ll;
	
	
	private List<BankListResponse> infos = new ArrayList<BankListResponse>();
	private int checkId = 0;

	@Override
	protected int setTitleImg() {
		// TODO Auto-generated method stub
		return R.drawable.btn_xing;
	}

	@Override
	protected String setTitle() {
		// TODO Auto-generated method stub
		return "选择帐号";
	}

	@Override
	protected View addCenterView() {
		infos = (ArrayList<BankListResponse>) getIntent().getSerializableExtra("list");
		checkId = getIntent().getIntExtra("checkId", 0);
		
		setBottomVisibility(View.GONE);
		
		view = LayoutInflater.from(getContext()).inflate(R.layout.senior_zhuihao, null);
		num_tv = (TextView) view.findViewById(R.id.seniorzhuihao_num_tv);
		num_tv.setText("共 "+infos.size()+" 个");
		num_tv.setTextSize(12);
		ll = (LinearLayout) view.findViewById(R.id.seniorzhuihao_ll);
		for (int i = 0; i < infos.size(); i++) {
			ll.addView(addItemView(i));
		}
		
		return view;
	}

	@Override
	protected void onClickSure() {
		// TODO Auto-generated method stub
		Intent intent = new Intent(getContext(), WithdrawCashActivity.class);
		intent.putExtra("checkId", checkId);
		setResult(0, intent);
		finish();
	}

	@Override
	protected void onClickCancel() {
		// TODO Auto-generated method stub
		onBackPressed();
	}
	
	private View addItemView(final int i){
		BankListResponse info = infos.get(i);
		View itemView = LayoutInflater.from(getContext()).inflate(R.layout.tixian_bank_item, null);
		LinearLayout ll = (LinearLayout) itemView.findViewById(R.id.tixian_bank_item_ll);
		TextView num_tv = (TextView) itemView.findViewById(R.id.tixian_bank_item_num);
		LinearLayout a_ll = (LinearLayout) itemView.findViewById(R.id.tixian_bank_item_a_ll);
		LinearLayout b_ll = (LinearLayout) itemView.findViewById(R.id.tixian_bank_item_b_ll);
		TextView a_num_tv = (TextView) itemView.findViewById(R.id.tixian_bank_item_a_num);
		
		num_tv.setText((i+1)+"");
		
		TextView bankName = (TextView) itemView.findViewById(R.id.tixian_bank_item_name);
		TextView bankWeiHao = (TextView) itemView.findViewById(R.id.tixian_bank_item_weihao);
		if (info.getDrawType() == 2) {
			bankName.setText("支付宝");
			a_ll.setVisibility(View.VISIBLE);
			b_ll.setVisibility(View.GONE);
			String bankCard = info.getBankCard();
			a_num_tv.setText(PublicMethod.tv_yinCang(bankCard, 3, 3));
		}else{
			bankName.setText(info.getBankName());
			a_ll.setVisibility(View.GONE);
			b_ll.setVisibility(View.VISIBLE);
			String bankCard = info.getBankCard();
			bankWeiHao.setText(bankCard.subSequence(bankCard.length()-3, bankCard.length()));
//			a_num_tv.setText(bankCard);
		}
		
		

		
		final ImageView check_iv = (ImageView) itemView.findViewById(R.id.tixian_bank_item_check_iv);
		if (checkId == i) {
			check_iv.setImageResource(R.drawable.zst_radio_checked);
		}else{
			check_iv.setImageResource(R.drawable.zst_radio_normal);
		}
		
		ll.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				checkId = i;
				onClickSure();
			}
		});
		
		return itemView;
	}
	
	
	

}
